﻿using System.Collections.Generic;
using BattleFury.Layers;

namespace BattleFury.Collections
{
	public class LayerCollection
	{
		protected readonly IList<string> Keys = new List<string>();
		protected readonly IList<ILayer> Values = new List<ILayer>();

		public int Count
		{
			get { return Values.Count; }
		}

		public bool IsReadOnly
		{
			get { return Values.IsReadOnly; }
		}

		public ILayer this[ILayer key]
		{
			get { return Values[IndexOf(key)]; }
			set { Values[IndexOf(key)] = value; }
		}

		public ILayer this[int index]
		{
			get { return Values[index]; }
			set { Values[index] = value; }
		}

		public IEnumerator<ILayer> GetEnumerator()
		{
			return Values.GetEnumerator();
		}

		public virtual ILayer Add(string key, ILayer item)
		{
			Keys.Add(key);
			Values.Add(item);
			return item;
		}

		public void Clear()
		{
			Values.Clear();
			Keys.Clear();
		}

		public bool Contains(ILayer item)
		{
			return Values.Contains(item);
		}

		public bool ContainsKey(string key)
		{
			return Keys.Contains(key);
		}

		public bool Remove(ILayer item)
		{
			Keys.RemoveAt(Values.IndexOf(item));
			return Values.Remove(item);
		}

		public int IndexOf(ILayer item)
		{
			return Values.IndexOf(item);
		}

		public int IndexOf(string key)
		{
			return Keys.IndexOf(key);
		}

		public void RemoveAt(int index)
		{
			Keys.RemoveAt(index);
			Values.RemoveAt(index);
		}
	}
}